package com.dragon.logical.service.website.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.common.model.ResultCode;
import com.dragon.common.model.exception.CustomException;
import com.dragon.logical.service.website.IDisplayProductService;
import com.dragon.repository.entity.DisplayProduct;
import com.dragon.repository.mapper.DisplayProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 3D产品展示 服务实现类
 * </p>
 *
 * @author sy
 * @since 2024-03-01
 */
@Service
public class DisplayProductServiceImpl extends ServiceImpl<DisplayProductMapper, DisplayProduct> implements IDisplayProductService {

    @Autowired
    DisplayProductMapper displayProductMapper;

    @Override
    public List<DisplayProduct> displayProductList() {
        return displayProductMapper.selectList(null);
    }

    @Override
    public void displayProductAdd(DisplayProduct displayProduct) {
        displayProduct.setCreateTime(DateUtil.date());
        displayProductMapper.insert(displayProduct);
    }

    @Override
    public void displayProductUpdate(DisplayProduct displayProduct) {
        displayProduct.setUpdateTime(DateUtil.date());
        displayProductMapper.updateById(displayProduct);
    }

    @Override
    public void displayProductDeleted(Integer id) {
        DisplayProduct displayProduct = displayProductMapper.selectById(id);
        if (displayProduct == null){
            throw new CustomException(ResultCode.DATA_NOT_FOUND);
        }
        displayProductMapper.deleteById(id);
    }
}
